<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<!-- 父组件模板 -->
		<div id="app">
			<cpn @item-click="cpnclick"></cpn>
		</div>
		<!-- 子组件模板 -->
		<template id="cpn">
			<div >
				<button v-for="item in categories"
						@Click="btnClick(item)">
						{{item.name}}
				</button>
			</div>
		</template>
	<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		//子组件
		const cpn ={
			template:'#cpn',
			data(){
				return{
					categories:[
						{id:'aaa',name:'123'},
						{id:'bbb',name:'45'},
						{id:'ccc',name:'56'},
						{id:'ddd',name:'789'}
					]
				}
			},
			methods:{
				btnClick(item){
					this.$emit('item-click',item)
				}
			}
		}
		//父组件
		const app = new Vue({
			el:'#app',
			data:{
				message:'你好'
			},
			components:{
				cpn
			},
			methods:{
				cpnclick(item){
					console.log('cpnclick',item)
				}
			}
		})
	</script>
	
	
	</body>
</html>
